package com.easy;

/**
 * Created by Lxk on 2019/6/8.
 */
public class Solution434 {

    public int countSegments(String s) {
        if(s==null || "".equals(s)){
            return 0;
        }
        s = s.trim();
        StringBuffer sb = new StringBuffer();
        boolean isSpace = false;
        for(int i = 0;i < s.length(); i++){
            if(s.charAt(i)==' '){
                if(isSpace){
                    continue;
                }else{
                    isSpace = true;
                    sb.append(s.charAt(i));
                }
            }else{
                isSpace = false;
                sb.append(s.charAt(i));
            }
        }
        System.out.println(sb.toString());
        return "".equals(sb.toString()) ? 0 : sb.toString().split(" ").length;
    }

    public static void main(String[] args) {
        Solution434 solution434 = new Solution434();
        solution434.countSegments("            ");
    }

}
